home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / torus-sr.tar / torus-sr / torus / opt.c < prev    next >
Text File  |  1991-06-19  |  3KB  |  120 lines

  1. # include "robots.h"
  2.  
  3. /*
  4.  * opt.c: do a psuedo ROGUEOPTS sort of thing
  5.  */
  6.  
  7. typedef struct Opt {
  8.     char    *name;
  9.     int    type;
  10. } Opt;
  11.  
  12. Opt    options[] = {
  13. # define    OPT_NAME    1
  14.     "name",        OPT_NAME,    /* Who am i boss ? */
  15. # define    OPT_MOVE_HEAP    2
  16.     "moveheaps",    OPT_MOVE_HEAP,    /* can push heaps */
  17. # define    OPT_NOMOVE_HEAP    3
  18.     "nomoveheaps",    OPT_NOMOVE_HEAP,/* can't push heaps */
  19. # define    OPT_SHOW_HSCORE 4
  20.     "showhscore",    OPT_SHOW_HSCORE,
  21. # define    OPT_NOSHOW_HSCORE 5
  22.     "noshowhscore", OPT_NOSHOW_HSCORE,
  23. # define        OPT_HSEW        6
  24.     "hsew",        OPT_HSEW,
  25. # define        OPT_NOHSEW      7
  26.     "nohsew",      OPT_NOHSEW,
  27. # define        OPT_VSEW        8
  28.     "vsew",        OPT_VSEW,
  29. # define        OPT_NOVSEW      9
  30.     "novsew",      OPT_NOVSEW,
  31. # define        OPT_WIMPY       10
  32.         "wimpy",        OPT_WIMPY,
  33. # define        OPT_STUDLY      11
  34.         "studly",       OPT_STUDLY,
  35. # define        OPT_CONT        12
  36.         "continuous",   OPT_CONT,
  37. # define        OPT_NOCONT      13
  38.     "nocontinuous", OPT_NOCONT,
  39.     0,        0
  40. };
  41.  
  42. /* get_robot_opts: Personalise robots to the users tastes. Model after
  43.  * the rogue/urogue type environment stuff. 
  44.  */
  45.  
  46. get_robot_opts(str)
  47. char    *str;
  48. {
  49.     register char     *p;
  50.     Opt    *op;
  51.     int    len, len2;
  52.  
  53.     p = str;
  54.     while(*p)
  55.     {
  56.         while(*p && !isalpha(*p)) p++;  /* skip non-alphas */
  57.         str = p;
  58.  
  59.         while(isalpha(*p)) p ++;    /* match longest word */
  60.         len = p - str;
  61.  
  62.         for(op = options; op->name; op ++)    /* see if defined */
  63.             if( strncmp(str, op->name, len) == 0)
  64.                 break;
  65.         if( op->name == NULL)
  66.             continue;
  67.         switch(op->type)    /* OK, now do something */
  68.         {
  69.             case OPT_NAME:
  70.                 while(*p == '=') p++;    /* skip ='s */
  71.                 str = p;    /* OK, now look for name */
  72.                 while(*p && *p != ',') p++;
  73.                 len2 = (MAXSTR - 1) -
  74.                     (strlen(my_user_name) + 4);
  75.                 len = p - str;
  76.                 len = len < len2 ? len : len2;
  77.                 (void) sprintf(whoami, "%.*s (%s)", len,
  78.                     str, my_user_name);
  79.                 break;
  80.             case    OPT_MOVE_HEAP:
  81.                 moveable_heaps = TRUE;
  82.                 break;
  83.             case    OPT_NOMOVE_HEAP:
  84.                 moveable_heaps = FALSE;
  85.                 break;
  86.             case    OPT_SHOW_HSCORE:
  87.                 show_highscore = TRUE;
  88.                 break;
  89.             case    OPT_NOSHOW_HSCORE:
  90.                 show_highscore = FALSE;
  91.                 break;
  92.             case    OPT_HSEW:
  93.                 hsew = TRUE;
  94.                 break;
  95.             case    OPT_NOHSEW:
  96.                 hsew = FALSE;
  97.                 break;
  98.             case    OPT_VSEW:
  99.                 vsew = TRUE;
  100.                 break;
  101.             case    OPT_NOVSEW:
  102.                 vsew = FALSE;
  103.                 break;
  104.             case    OPT_WIMPY:
  105.                 wimpy = TRUE;
  106.                 break;
  107.             case    OPT_STUDLY:
  108.                 wimpy = FALSE;
  109.                 break;
  110.             case    OPT_CONT:
  111.                 continuous = TRUE;
  112.                 break;
  113.             case    OPT_NOCONT:
  114.                 continuous = FALSE;
  115.                 break;
  116.         }
  117.     }
  118. }
  119.  
  120.